package fashionshop.gui.common.component;

import java.util.List;

import javax.swing.JDialog;

import org.apache.commons.lang3.StringUtils;

import fashionshop.gui.common.event.DialogSubmitListener;
import fashionshop.gui.common.util.MessageBoxUtil;

@SuppressWarnings("serial")
public abstract class CallbackDialog<E> extends JDialog {
	
	protected DialogSubmitListener<E> listener;
	
	public abstract void populateData(E entity);
	
	public abstract void updateForm(E entity);

	public abstract List<String> validateForm();
	
	public void submit(){
		List<String> msgs = validateForm();
		if(msgs == null){
			if(listener != null){
				listener.dialogSubmitCallback(this);
			}
		}else{
			String msg = StringUtils.join(msgs, "\n");
			MessageBoxUtil.alert(CallbackDialog.this, msg);
		}
	}
	
}
